package com.crazy.crazytransactionservice.message;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;


/**
 * @Date: 2024-05-13-14:06
 * @Author: Zheng Zeliang
 */
@Slf4j
public class InitRabbitMQ {
    public static void doInit(){
        try {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            String EXCHANGE_NAME = "confirm_exchange";
            channel.exchangeDeclare(EXCHANGE_NAME,"direct");

            String queueName1 = "subscribe_queue";
            channel.queueDeclare(queueName1,true,false,false,null);
            channel.queueBind(queueName1,EXCHANGE_NAME,"subscribe_key");

            String queueName2 = "redeem_queue";
            channel.queueDeclare(queueName2,true,false,false,null);
            channel.queueBind(queueName2,EXCHANGE_NAME,"redeem_key");
            log.info("消息队列启动成功");
        } catch (Exception e) {
            log.info("消息队列启动失败");
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        doInit();
    }
}
